package s47.dqj.dao;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

import s47.dqj.bean.PatientOrder;
/**
 * 19.挂号表
 * @author Administrator
 *
 */
@Repository("patientOrderDaoImpl")
public class PatientOrderDaoImpl extends HibernateDaoSupport implements PatientOrderDaoInf {

	/* (non-Javadoc)
	 * @see s47.dqj.dao.PatientOrderDaoInf#setSupperSessionFactory(org.hibernate.SessionFactory)
	 */
	@Override
	@Resource(name="sessionFactory")
	public void setSupperSessionFactory(SessionFactory sessionFactory){
		super.setSessionFactory(sessionFactory);
	}
	/* (non-Javadoc)
	 * @see s47.dqj.dao.PatientOrderDaoInf#findAllByCondition(java.lang.String, java.lang.Integer)
	 */
	@Override
	public List<PatientOrder> findAllByCondition(String hql,Integer pageNum){
		Query query=getSession().createQuery(hql);
		query.setFirstResult((Integer.valueOf(pageNum)-1)*20);
		query.setMaxResults(20);
		return query.list();
	}
	
	/* (non-Javadoc)
	 * @see s47.dqj.dao.PatientOrderDaoInf#selectPageTotal(java.lang.String)
	 */
	@Override
	public List<Integer> selectPageTotal(String tempHQL){
		List<Integer> pageTotal=new ArrayList<Integer>();
		int p;
		Long temp;
		String hql="select Count(*) from PatientOrder as po"+tempHQL;
		Query query=getSession().createQuery(hql);
		temp=(Long)query.uniqueResult();
		
		if(temp%20!=0)
			p=(int)(temp/20+1);
		else
			p=(int)(temp/20);
		for(int n=0;n<p;n++){
			pageTotal.add(n+1);
		}
		return pageTotal;
	}  
	/* (non-Javadoc)
	 * @see s47.dqj.dao.PatientOrderDaoInf#save(s47.dqj.bean.PatientOrder)
	 */
	@Override
	public void save(PatientOrder patientOrder){
		getHibernateTemplate().save(patientOrder);
	}
	/* (non-Javadoc)
	 * @see s47.dqj.dao.PatientOrderDaoInf#update(s47.dqj.bean.PatientOrder)
	 */
	@Override
	public void update(PatientOrder patientOrder){
		getHibernateTemplate().update(patientOrder);
	}
	/* (non-Javadoc)
	 * @see s47.dqj.dao.PatientOrderDaoInf#delete(s47.dqj.bean.PatientOrder)
	 */
	@Override
	public void delete(PatientOrder patientOrder){
		getHibernateTemplate().delete(patientOrder);
	}
	/* (non-Javadoc)
	 * @see s47.dqj.dao.PatientOrderDaoInf#findObject(s47.dqj.bean.PatientOrder)
	 */
	@Override
	public PatientOrder findObject(PatientOrder patientOrder){
		return getHibernateTemplate().get(PatientOrder.class, patientOrder.getPoid());
	}
}
